package www.reagnetbox.com.view;

import android.content.Context;
import android.text.TextUtils;
import android.widget.EditText;

import com.lxj.xpopup.core.CenterPopupView;
import com.lxj.xpopup.util.XPopupUtils;

import www.reagnetbox.com.R;
import www.reagnetbox.com.callback.ColRowCallback;
import www.reagnetbox.com.util.XPopupUtil;

public class EnterRowColPopup extends CenterPopupView {
    Context context;
    ColRowCallback callback;
    private EditText etCol;
    private EditText etRow;

    public EnterRowColPopup(Context context, ColRowCallback callback) {
        super(context);
        this.callback = callback;
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.popup_enter_row_col;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        findViewById(R.id.tv_back).setOnClickListener(v -> dismiss());
        etCol = findViewById(R.id.et_col);
        etRow = findViewById(R.id.et_row);
        findViewById(R.id.tv_ok).setOnClickListener(v -> {
            if (checkRequire()) {
                dismiss();
                int col = Integer.parseInt(etCol.getText().toString());
                int row = Integer.parseInt(etRow.getText().toString());
                callback.fun(col,row);
            }
        });
    }


    @Override
    protected int getMaxWidth() {
        return (int) (XPopupUtils.getScreenWidth(getContext()) * .25f);
    }

    @Override
    protected int getMaxHeight() {
        return (int) (XPopupUtils.getScreenHeight(getContext()) * .60f);
    }

    private boolean checkRequire(){
        if (TextUtils.isEmpty(etCol.getText())) {
            XPopupUtil.showKnowPopup(context, "库列不能为空");
            return false;
        }
        if (TextUtils.isEmpty(etRow.getText())) {
            XPopupUtil.showKnowPopup(context, "库行不能为空");
            return false;
        }
        return true;
    }
}
